import { request } from '@/api/request';
import { PlateColorGroup } from '@/common';
import { useState } from 'react';
import { useNavigate } from 'react-router-dom';
import type { YmColumnsType } from 'ym-design';
import { YmTable } from 'ym-design';
type RecordType = {
  safetyIndexCarId: string;
  plateNumber: string;
  plateColor: string;
  safetyIndex: number;
  entName: string;
  coopType: number;
  vehicleLicenseOwner: string;
  createTime: string;
  carId: string;
};
const CarList = ({ entId }: { entId: string }) => {
  const navigator = useNavigate();
  const [columns] = useState<YmColumnsType<RecordType>>([
    {
      title: '车牌号',
      dataIndex: 'plateNumber',
      ellipsis: true,
      key: 'plateNumber',
      render(value, record, index) {
        return (
          <span
            className="safe-edu_table_operation_text"
            onClick={() => {
              navigator(
                `/safeIndex/safeIndexStatistics/carIndexInfo?plateNumber=${value}&entId=${entId}&carId=${record.carId}&safetyIndexCarId=${record.safetyIndexCarId}`,
              );
            }}
          >
            {value}
          </span>
        );
      },
    },
    {
      title: '车牌颜色',
      dataIndex: 'plateColor',
      key: 'plateColor',
      render: (text, record) => <span>{text ? PlateColorGroup[Number(text)] : '--'}</span>,
    },
    {
      title: '车辆安全指数',
      dataIndex: 'safetyIndex',
      ellipsis: true,
      key: 'safetyIndex',
    },
    {
      title: '所属企业',
      dataIndex: 'entName',
      ellipsis: true,
      key: 'entName',
    },
    {
      title: '车企关系',
      dataIndex: 'coopType',
      ellipsis: true,
      key: 'coopType',
      render: (text, record) => <span>{text == 51 ? '自有车' : text == 52 ? '外协车辆' : '--'}</span>,
    },
    {
      title: '行驶证所有人',
      dataIndex: 'ownerLicense',
      ellipsis: true,
      key: 'ownerLicense',
    },
    {
      title: '创建时间',
      dataIndex: 'createTime',
      ellipsis: true,
      key: 'createTime',
    },
  ]);
  const [tableDep, _reFreshTable] = useState<number>();

  return (
    <YmTable
      style={{ minHeight: '600px ' }}
      wrapperStyle={{ padding: 0 }}
      columns={columns}
      request={async ({ page }, form) => {
        const { data } = await request<{ list: any[]; total: number }>({
          url: '/unicron/ent/safetyIndex/entCarList',
          data: {
            entId,
            ...page,
          },
        });
        return data;
      }}
      requestOptions={{
        reFreshDep: [tableDep],
        defaultPageSize: 10,
      }}
      rowKey="safetyIndexCarId"
    />
  );
};
export default CarList;
